<?php

use Biz\service\FineGoodsBrokeNews\FineGoodsBrokeNewsService;
use Doraemon\model\ForbiddenWord\ForbiddenSceneWord as ForbiddenSceneWordModel;
use Doraemon\service\ForbiddenWord\ForbiddenSceneWord;
use Biz\cache\brand\BrandShowActivity;

/**
 * @deprecated
 */
class SaveAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    /**
     * @throws \Exception
     */
    public function main()
    {
        if (!BrandShowActivity::isLock($this->uid . '-goodsBrokeNews', 2)) {
            $data = $this->getRequest()->getPost('data', '[]');
            $uid = $this->uid;
            //参数验证
            if (empty($data)) {
                throw new \Exception("参数错误！");
            }
            $remarkForbidden = new ForbiddenSceneWord(ForbiddenSceneWordModel::CONTENT, $data);
            if ($remarkForbidden->getHit() && !$remarkForbidden->getPublish()) {
                throw new \Exception("推荐理由含有禁用词！");
            }
            if (!$uid) {
                throw new \Exception("请登录重试！");
            }
            //组装数据
            $queryData['data'] = $data;
            $queryData['uid'] = $uid;

            FineGoodsBrokeNewsService::saveData($queryData);
            $this->setSuccess(1);
        } else {
            throw new \Exception('你的操作太频繁');
        }
    }
}